# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=mercury
pkgver=2.11.1.r0.g5f068af
pkgrel=1
epoch=1
pkgdesc='Network metadata capture and analysis.'
arch=('x86_64' 'aarch64')
groups=('blackarch' 'blackarch-fingerprint' 'blackarch-networking'
        'blackarch-sniffer')
url='https://github.com/cisco/mercury'
license=('custom:unknown')
depends=('gmp' 'openssl' 'zlib')
makedepends=('git' 'clang' 'gcc' 'python-pip' 'tcpreplay' 'valgrind')
source=("git+https://github.com/cisco/$pkgname.git")
backup=("etc/$pkgname/$pkgname.cfg")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd $pkgname

  git submodule init
  git config "submodule.$pkgname/include/$submodule.url" "$srcdir/$submodule"
  git -c protocol.file.allow=always submodule update

  ./configure --prefix=/usr
}

build() {
  cd $pkgname

  make -j1
}

package() {
  cd $pkgname

  install -Dm 755 "src/$pkgname" "$pkgdir/usr/bin/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" doc/{*.md,*.pdf} *.md
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  install -Dm 644 "$pkgname.cfg" "$pkgdir/etc/$pkgname/$pkgname.cfg"
  install -Dm 644 $pkgname \
    "$pkgdir/usr/share/bash-completion/completions/$pkgname"
  install -Dm 644 install_mercury/mercury.service \
    "$pkgdir/usr/lib/systemd/system/$pkgname.service"
}

